package com.fhz.mvvm.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.fhz.mvvm.R
import com.fhz.mvvm.databinding.RvLayoutBinding
import com.fhz.mvvm.entity.User

/**
 * 时间:2023/3/28
 * @author Mr.Feng
 * 简述: 适配器
 */
class UserAdapter(val user: User) : RecyclerView.Adapter<UserAdapter.ViewHolder>() {


    inner class ViewHolder(var binding: RvLayoutBinding) : RecyclerView.ViewHolder(binding.root) {
         //单个赋值
//        var name:TextView = binding.rvNameTv
//        var headImage:ImageView = binding.rvImageHead

       fun bind(user: User){
            binding.user = user
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflate = DataBindingUtil.inflate<RvLayoutBinding>(
            LayoutInflater.from(parent.context),
            R.layout.rv_layout,
            parent,
            false
        )
        return ViewHolder(inflate)

    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
//        val user = listUser[position]
        holder.bind(user)
    }

    override fun getItemCount() = 1


}